<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">











<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0f81ff2f.js","daovoice")
  daovoice('init', {
      app_id: "9c84d93b"
    });
  daovoice('update');
  </script>












<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=6.1.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.1.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=6.1.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=6.1.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.1.0" color="#222">







<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>


<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '6.1.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="java内存管理以及常量池java的内存管理就是对象的分配与释放问题。  在java中内存的分配由程序完成的，而内存的释放是由垃圾回收器（Garbage Collection,GC)完成的。 java虚拟机将其管辖的内存大致分为了三个逻辑部分： 1.方法区（Method Area）2.Java栈（Stack）3.Java堆（Heap）  目录： [TOC]  1.方法区方法区是静态分配的，编译器将">
<meta name="keywords" content="java">
<meta property="og:type" content="article">
<meta property="og:title" content="java内存管理以及常量池">
<meta property="og:url" content="http://zhangsnke.gitee.io/2018/04/04/java2/index.html">
<meta property="og:site_name" content="Zhangsnke&#39;s Blog">
<meta property="og:description" content="java内存管理以及常量池java的内存管理就是对象的分配与释放问题。  在java中内存的分配由程序完成的，而内存的释放是由垃圾回收器（Garbage Collection,GC)完成的。 java虚拟机将其管辖的内存大致分为了三个逻辑部分： 1.方法区（Method Area）2.Java栈（Stack）3.Java堆（Heap）  目录： [TOC]  1.方法区方法区是静态分配的，编译器将">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://wx4.sinaimg.cn/mw690/0060lm7Tly1fq7cj0nii0j30mr0cs3yq.jpg">
<meta property="og:image" content="https://s1.ax1x.com/2018/04/10/CFeUnH.jpg">
<meta property="og:updated_time" content="2018-04-11T08:40:49.857Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java内存管理以及常量池">
<meta name="twitter:description" content="java内存管理以及常量池java的内存管理就是对象的分配与释放问题。  在java中内存的分配由程序完成的，而内存的释放是由垃圾回收器（Garbage Collection,GC)完成的。 java虚拟机将其管辖的内存大致分为了三个逻辑部分： 1.方法区（Method Area）2.Java栈（Stack）3.Java堆（Heap）  目录： [TOC]  1.方法区方法区是静态分配的，编译器将">
<meta name="twitter:image" content="http://wx4.sinaimg.cn/mw690/0060lm7Tly1fq7cj0nii0j30mr0cs3yq.jpg">






  <link rel="canonical" href="http://zhangsnke.gitee.io/2018/04/04/java2/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>java内存管理以及常量池 | Zhangsnke's Blog</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/zxk318www"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zhangsnke's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>




<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
          
  
  <li class="menu-item menu-item-home menu-item-active">
    <a href="/blog/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-about">
    <a href="/blog/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-tags">
    <a href="/blog/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-categories">
    <a href="/blog/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-archives">
    <a href="/blog/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
</li>

      

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zhangsnke.gitee.io/blog/2018/04/04/java2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Zhangsnke">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://wx1.sinaimg.cn/mw690/0060lm7Tly1fz2r82s43bj30u20u0ad9.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zhangsnke's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">java内存管理以及常量池</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-04T14:42:13+08:00">2018-04-04</time>
            

            
            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/java基础知识/" itemprop="url" rel="index"><span itemprop="name">java基础知识</span></a></span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2018/04/04/java2/#comments" itemprop="discussionUrl">
                  <span class="post-meta-item-text">评论数：</span> <span class="post-comments-count valine-comment-count" data-xid="/blog/2018/04/04/java2/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="java内存管理以及常量池"><a href="#java内存管理以及常量池" class="headerlink" title="java内存管理以及常量池"></a><strong>java内存管理以及常量池</strong></h1><font color="red"><strong>java的内存管理就是对象的分配与释放问题。</strong></font>

<p>在java中内存的分配由程序完成的，而内存的释放是由垃圾回收器（Garbage Collection,GC)完成的。</p>
<p>java虚拟机将其管辖的内存大致分为了三个逻辑部分：</p>
<p>1.方法区（Method Area）<br>2.Java栈（Stack）<br>3.Java堆（Heap）</p>
<hr>
<p>目录：</p>
<p>[TOC]</p>
<hr>
<h1 id="1-方法区"><a href="#1-方法区" class="headerlink" title="1.方法区"></a><strong><font color="blue">1.方法区</font></strong></h1><p>方法区是静态分配的，编译器将变量绑定在某个存储位置上，而且这些绑定不会在运行时改变。<font color="red">常量池、源代码中的命名常量、String常量、代码段和数据段、静态域（用来存放static定义的静态成员）</font>都放在方法区。</p>
<p>常量池（constant pool）<br>常量池指的是在编译期就被确定，并保存在已编译的.class文件中的一些数据。处理包含代码中所定义的各类基本类型（如int、long等等）和对象型（如String及数组）的常量值（final）还包含一些以文本形式出现的符号引用，比如：</p>
<ul>
<li>类和接口的全限定名</li>
<li>字段的名称和描述符</li>
<li>方法和名称和描述符</li>
<li>类和接口的全限定名</li>
</ul>
<h1 id="2-Java栈"><a href="#2-Java栈" class="headerlink" title="2.Java栈"></a><strong><font color="blue">2.Java栈</font></strong></h1><p>Java栈是一个逻辑感念，<font color="red">特点是后进先出</font>。<br>一个栈的空间可能是连续的，也可能不是。用来保存局部变量的值，包括：1.用来保存基本数据类型的值；2.存放基本类型的数据和对象的引用，但对象本身不存放在栈中，而是存放在堆中。栈的优势：存取速度要比堆快。缺点：存在栈中的数据大小与生存期必须是确定的，缺乏灵活性。</p>
<h1 id="3-Java堆"><a href="#3-Java堆" class="headerlink" title="3.Java堆"></a><strong><font color="blue">3.Java堆</font></strong></h1><p>堆分配意味着随意的顺序，在运行时进行存储空间分配和收回的内存管理模型。Java堆用来存放动态产生的数据，比方通过new关键字创建出来的对象。注意创建出来的对象只包含属于各自的成员变量，并不包括成员方法，因为同一个类的对象拥有各自的成员变量，存储在各自的堆中，但是他们共享该类的方法，并不是每创建一个对象就把成员方法复制一次。堆是由垃圾回收来负责的，堆的优势是可以动态地分配内存大小，生存期也不必事先告诉编译器，因为它是在运行时动态分配内存的，Java的垃圾收集器会自动地收走这些不再使用的数据，但缺点是在运行时动态分配内存，存取速度较慢。</p>
<hr>
<h1 id="4-Java的内存垃圾回收机制"><a href="#4-Java的内存垃圾回收机制" class="headerlink" title="4.Java的内存垃圾回收机制"></a><strong>4.Java的内存垃圾回收机制</strong></h1><p>Java的内存垃圾回收机制是从程序的主要运行对象开始检查引用链，当遍历一遍发现<font color="green">没有被引用的孤立对象</font>就作为垃圾回收。GC为了能够正确释放对象，必须监控每一个对象的运行状态，包括对象的申请、引用、被引用、赋值等。监视对象状态是为了更加准确、及时地释放对象，而释放对象的<strong>根本原则</strong>就是该对象不在被引用</p>
<hr>
<h1 id="5-内存泄露"><a href="#5-内存泄露" class="headerlink" title="5.内存泄露"></a><strong>5.内存泄露</strong></h1><p>在Java中，内存泄露就是存在一些被分配的对象，这些对象有以下两个特点：</p>
<ol>
<li>这些对象是可达的，即<font color="red">引用指向</font></li>
<li>这些对象是无用的，即<font color="red">程序以后不会再使用这些对象</font></li>
</ol>
<p>如果满足这两个条件，这些对象就可以被判定为Java中的内存泄露，这些对象不会被GC所回收，但是它却仍然占用内存</p>
<hr>
<h1 id="6-字符串的内存分配与常量池"><a href="#6-字符串的内存分配与常量池" class="headerlink" title="6.字符串的内存分配与常量池"></a><strong><font color="red">6.字符串的内存分配与常量池</font></strong></h1><p>对于字符串，其对象的引用都是存储在栈中的，如果是编译期已经创建好的就存储在常量池（如：直接用双引号定义的或者final修饰并且能在编译期就能确定的），如果在运行期间才能确定好就存储在堆中（如：new关键字创建出来的）。对于equals相等的字符串，在常量池中永远只有一份，在堆中有多份。</p>
<p>如以下代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">String s1 = <span class="string">"Hello"</span>;</span><br><span class="line">String s2 = <span class="string">"Hello"</span>;</span><br><span class="line">String s3 = <span class="string">"Hello"</span>;</span><br><span class="line"></span><br><span class="line">String s4 = <span class="keyword">new</span> String(<span class="string">"Hello"</span>);</span><br><span class="line">String s5 = <span class="keyword">new</span> String(<span class="string">"Hello"</span>);</span><br><span class="line">String s6 = <span class="keyword">new</span> String(<span class="string">"Hello"</span>);</span><br></pre></td></tr></table></figure></p>
<p>分析：s1、s2、s3在编译期就能确定，在创建对象时，现在厂里吃重寻找到相同的值，若没有，则在常量池中创建一个对象。对于通过new产生的一个字符串，会先去常量池中查找是否已经有这个对象（此处”Hello”），如果没有则在常量池中创建一个此字符串对象，然后堆中创建一个常量池中的此对象（此处“Hello”）的拷贝对象。</p>
<p><img src="http://wx4.sinaimg.cn/mw690/0060lm7Tly1fq7cj0nii0j30mr0cs3yq.jpg" alt="图1"></p>
<p>若要问：？String s = new String(“Hello”)这个语句产生了几个对象？<br>答案：一个或两个，若果常量池中原来没有“Hello”，那就是两个。</p>
<p>存在于.class文件中的常量池，在运行期被JVM装载，并且可以扩充String类的intern()方法就是扩充常量池的一个方法；当一个String实例str调用intern()方法时，Java查找常量池中是否有相同Unicode的字符串常量，若果有，则返回其引用，如果没有，则在常量池中增加一个Unicode等于str的字符串并返回它的引用。</p>
<p>如下代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">String s0= <span class="string">"Java"</span>;</span><br><span class="line">String s1=<span class="keyword">new</span> String(<span class="string">"Java"</span>);</span><br><span class="line">String s2=<span class="keyword">new</span> String(<span class="string">"Java"</span>);</span><br><span class="line"></span><br><span class="line">s2=s2.intern();        <span class="comment">//把常量池中"Hello"的引用赋给s2</span></span><br><span class="line"></span><br><span class="line">System.out.println( s0==s1);</span><br><span class="line">System.out.println( s0==s1.intern() );</span><br><span class="line">System.out.println( s0==s2);</span><br></pre></td></tr></table></figure></p>
<p>运行结果</p>
<blockquote>
<p>false<br>true<br>true</p>
</blockquote>
<hr>
<p>String常量池问题的例子：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">【<span class="number">1</span>】</span><br><span class="line">String s0 = <span class="string">"HelloWorld"</span>;</span><br><span class="line">String s1 = <span class="string">"World"</span>;</span><br><span class="line">String s2 = <span class="string">"Hello"</span> + s1;</span><br><span class="line">System.out.println((s0 == s2));  <span class="comment">//结果为false</span></span><br><span class="line"></span><br><span class="line">【<span class="number">2</span>】</span><br><span class="line">String s0 = <span class="string">"HelloWorld"</span>;</span><br><span class="line"><span class="keyword">final</span> String s1 = <span class="string">"World"</span>;</span><br><span class="line">String s2 = <span class="string">"Hello"</span> + s1;</span><br><span class="line">System.out.println((s0 == s2)); <span class="comment">//结果为true</span></span><br><span class="line"></span><br><span class="line">【<span class="number">3</span>】</span><br><span class="line">String s0 = <span class="string">"HelloWorld"</span>;</span><br><span class="line"><span class="keyword">final</span> String s1 = getWorld();</span><br><span class="line">String s2 = <span class="string">"Hello"</span> + s1;</span><br><span class="line"></span><br><span class="line">System.out.println((s0== s2)); <span class="comment">//结果为false</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">getWorld</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">"World"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>分析：<br>【1】中，JVM对于字符串引用（由于在字符串的”+”连接中），有字符串引用存在，而引用的值在程序编译期是无法确定的，即“Hello”+s1无法被编译期优化，只有在程序运行期来动态分配并将连接后的新地址赋给s2。</p>
<p>【2】和【1】中唯一不同的是bb字符串加入了final修饰，对于final修饰的变量，它在编译时被解析为一个常量值的一个本地拷贝存储到自己的常量池中或嵌入到它的字节码流中。所以此时的“Hello”+s1和“Hello”+”World”效果是一样的。</p>
<p>【3】JVM对于字符串引用s1，虽然它为final修饰，但是它的值在编译期无法确定，只有在运行程序期调用方法后，将方法的返回值和“Hello”来动态连接并分配给地址s2。</p>
<p>对于字符串的操作，“abc”+”def”为三个字符串对象，第三个为“abcdef”。也就是说，在Java中对字符串的一切操作，都会产生一个新的字符串对象。String创建字符串时不可变的，任何对String的改变都会引发新的String对象的生产，而不是那些不用的未被引用的对象则为作为垃圾回收。</p>
<hr>
<h1 id="7-基本类型的变量和常量在内存中的分配"><a href="#7-基本类型的变量和常量在内存中的分配" class="headerlink" title="7.基本类型的变量和常量在内存中的分配"></a><strong>7.基本类型的变量和常量在内存中的分配</strong></h1><p>对于基本类型的变量和常量，变量和引用存储在栈中，常量存储在常量池中。</p>
<p>如以下代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> i1 = <span class="number">9</span>;</span><br><span class="line"><span class="keyword">int</span> i2 = <span class="number">9</span>;</span><br><span class="line"><span class="keyword">int</span> i3 = <span class="number">9</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">final</span> <span class="keyword">int</span> INT1 = <span class="number">9</span>;</span><br><span class="line"><span class="keyword">final</span> <span class="keyword">int</span> INT2 = <span class="number">9</span>;</span><br><span class="line"><span class="keyword">final</span> <span class="keyword">int</span> INT3 = <span class="number">9</span>;</span><br></pre></td></tr></table></figure></p>
<p>如图</p>
<p><img src="https://s1.ax1x.com/2018/04/10/CFeUnH.jpg" alt="图2"></p>
<p>编译器先处理int i1 = 9; 首先它会在栈中创建一个变量为i1的引用，然后查找栈中是否有9这个值，如果没找到，就将9存放进来，然后i1指向9。接着处理int i2 = 9；创建完i2的引用变量后，因为栈中已经有9这个值，便将i2直接指向9。这样，就出现了i1与i2同时均指向9的情况。最后i3也指向这个9。</p>
<p>基本类型和基本类型的包装类。基本类型有：byte、short、char、int、long、boolean。基本类型的包装类分别对应的是：Byte、Short、Character、Integer、Long、Boolean（注意区分大小写）</p>
<p>二者区别：<strong>基本类型体现在程序中的普通变量，基本类型的包装类是类，体现在程序中的引用变量。因此二者在内存中的存储位置不同：基本类型存储在栈中，而基本类型包装类存储在堆中。上边提到的这些包装类都实现了常量池技术，另外两种浮点数类型的包装类则没有实现。</strong></p>
<p>如下代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Integer i1=<span class="number">10</span>;</span><br><span class="line">Integer i2=<span class="number">10</span>;</span><br><span class="line">Integer i3=<span class="keyword">new</span> Integer(<span class="number">10</span>);</span><br><span class="line">Integer i4=<span class="keyword">new</span> Integer(<span class="number">10</span>);</span><br><span class="line">System.out.print(i1==i2);   <span class="comment">//输出为true</span></span><br><span class="line">System.out.print(i2==i3);   <span class="comment">//输出为false</span></span><br><span class="line">System.out.print(i3==i4);   <span class="comment">//输出为false</span></span><br><span class="line">Double d1=<span class="number">1.0</span>;</span><br><span class="line">Double d2=<span class="number">1.0</span>;</span><br><span class="line">System.out.print(d1==d2);   <span class="comment">//输出为false</span></span><br></pre></td></tr></table></figure></p>
<p>分析：</p>
<ol>
<li>i1和i2均是引用类型，在栈中存储指针，因为Integer是包装类，由于Integer包装类实现了常量池技术，因此i1和i2的10均是从常量池中获取的，均指向同一个地址，因此i1=i2</li>
<li>i3和i4均是引用类型，在栈中存储指针，因为Integer是包装类。但是由于他们各自都是new出来的，因此不再从常量池寻找数据，而是从堆中各自new一个对象，然后各自保存指向对象的指针，所以i3和i4不相等，因此他们所存指针也不同，所指向的对象不同。</li>
<li>d1和d2均是引用类型，在栈中存储指针，因为Double是包装类，但Double包装类没有实现常量池技术，因此Double d1 = 1.0;相当于Double d1 = new Double(1.0);是从堆中new一个对象。</li>
</ol>
<hr>
<h1 id="8-成员变量和局部变量在内存中的分配"><a href="#8-成员变量和局部变量在内存中的分配" class="headerlink" title="8.成员变量和局部变量在内存中的分配"></a><strong>8.成员变量和局部变量在内存中的分配</strong></h1><p>对于成员变量和局部变量：成员变量就是方法外部，类的内部定义的变量；局部变量就是方法或语句块内部定义的变量。局部变量必须初始化。形式参数是局部变量。局部变量的数据存储在栈内存中。栈内存中的局部变量随着方法的消失而消失。成员变量存储在堆中的对象里面，由垃圾回收器负责回收。</p>
<hr>
<h1 id="9-与equals"><a href="#9-与equals" class="headerlink" title="9.==与equals()"></a><strong>9.==与equals()</strong></h1><ul>
<li>==是一个运算符</li>
<li>Equals则是String对象的方法</li>
</ul>
<p>比较无法就是两种情况：</p>
<ol>
<li>基本数据类型的比较</li>
<li>引用对象的比较</li>
</ol>
<p>1.基本数据类型比较</p>
<blockquote>
<p>==比较两个值是否相等，相等则为true，否则为false；而equals()是String类的额方法，不用来比较基本数据类型</p>
</blockquote>
<p>2.引用对象比较</p>
<blockquote>
<p>==比较两个对象是否指向内存中的同一个对象，即指向同一个地址；而equals()则比较String对象的内容是否相同</p>
</blockquote>
<p><font color="red">注意</font></p>
<ul>
<li><p>String是一个特殊的引用类型，对于两个字符串的比较，不管是==还是Equals，两者比较的都是字符串是否相同，例如下面的两个例子的输出结果都是true:</p>
<blockquote>
<p>System.out.println(“Hello”==”Hello”);<br>System.out.println(“Hello”.equals(“Hello”));</p>
</blockquote>
</li>
<li><p>当你创建两个String对象时，内存中的地址是不相同的，你可以赋相同的值。对弈字符串的内容相同，引用地址不一定相同（相同的内容的对象地址不一定相同），反过来，引用地址相同则内容一定相同。</p>
</li>
</ul>

      
    </div>

    

    
    
    

<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
  
</div>

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://wx4.sinaimg.cn/mw690/0060lm7Tly1fq7f9mgftqj30yf11x793.jpg" alt="Zhangsnke 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://wx2.sinaimg.cn/mw690/0060lm7Tly1fq7f9yogljj30ox0qi76z.jpg" alt="Zhangsnke 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/java/" rel="tag"><i class="fa fa-tag"></i> java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/04/03/java1/" rel="next" title="java中关于try、catch、finally的分析">
                <i class="fa fa-chevron-left"></i> java中关于try、catch、finally的分析
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/04/10/javaInterview1/" rel="prev" title="2017java面试题(技术面试）">
                2017java面试题(技术面试） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
      <div id="uyan_frame"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://wx1.sinaimg.cn/mw690/0060lm7Tly1fz2r82s43bj30u20u0ad9.jpg"
                alt="Zhangsnke" />
            
              <p class="site-author-name" itemprop="name">Zhangsnke</p>
              <p class="site-description motion-element" itemprop="description">java jsp</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives/">
                
                    <span class="site-state-item-count">11</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">4</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">8</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/zxk318www" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:1137824821@qq.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://weibo.com/u/3487862312" target="_blank" title="Weibo"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#java内存管理以及常量池"><span class="nav-number">1.</span> <span class="nav-text">java内存管理以及常量池</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#1-方法区"><span class="nav-number">2.</span> <span class="nav-text">1.方法区</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-Java栈"><span class="nav-number">3.</span> <span class="nav-text">2.Java栈</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-Java堆"><span class="nav-number">4.</span> <span class="nav-text">3.Java堆</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-Java的内存垃圾回收机制"><span class="nav-number">5.</span> <span class="nav-text">4.Java的内存垃圾回收机制</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-内存泄露"><span class="nav-number">6.</span> <span class="nav-text">5.内存泄露</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-字符串的内存分配与常量池"><span class="nav-number">7.</span> <span class="nav-text">6.字符串的内存分配与常量池</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-基本类型的变量和常量在内存中的分配"><span class="nav-number">8.</span> <span class="nav-text">7.基本类型的变量和常量在内存中的分配</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#8-成员变量和局部变量在内存中的分配"><span class="nav-number">9.</span> <span class="nav-text">8.成员变量和局部变量在内存中的分配</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#9-与equals"><span class="nav-number">10.</span> <span class="nav-text">9.==与equals()</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zhangsnke</span>

  

  
</div>




<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>
</div>
  <!-- <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.7.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Muse</a> v6.1.0</div>
-->





<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共28.7k字</span>
</div>
        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=6.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=6.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=6.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=6.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=6.1.0"></script>



  



	





  
    

    
      <!-- UY BEGIN -->
      <script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid=2161053"></script>
      <!-- UY END -->
    
  





  








  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  
  
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(function (item) {
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'V4OQTBV0QUJvAOnALRUDikMp-gzGzoHsz',
        appKey: 'Ygfy3JqhxL8KArimEFAGB3QQ',
        placeholder: 'ヾﾉ≧∀≦)o来啊，快活啊!',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  
  

  

  

  

  


<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
</body>
</html>

